//app.js
var qqsdk = require('/utils/qqmap-wx-jssdk.js');
var common = require('/utils/common.js');
var qqmapsdk;
var cities = [];
App({
  onLaunch: function () {
    qqmapsdk = new qqsdk({
      key: 'EJMBZ-QPFRP-RUYDA-VPHF3-YXXKE-3ZFYQ'
    });
    qqmapsdk.getCityList({
      success: function (res) {
        cities = res.result;
        console.log(cities)
        app.globalData.cities = cities
      },
      fail: function (res) {
        console.log("fail");
      },
      complete: function (res) {
        cities = res.result;
      }
    });

    // wx.getSetting({
    //   success: res => {
    //     if (res.authSetting['scope.userInfo']) {
    //       console.log(res);
    //       // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
    //       // app.globalData.getUserInfoFail = 3
    //       // if (app.userInfoReadyCallback) {
    //       //   console.log("callback马上回调1")
    //       //   app.userInfoReadyCallback()
    //       // }
    //     } else {
    //       /*wx.authorize({
    //         scope: 'scope.userInfo',
    //         success() {
    //           // 用户已经同意小程序获取用户信息，后续调用 接口不会弹窗询问
    //           if (app.userInfoReadyCallback) {
    //             console.log("callback马上回调1")
    //             app.userInfoReadyCallback()
    //           }
    //         },
    //         fail() {
    //           app.globalData.getUserInfoFail = 2
    //           if (app.userInfoReadyCallback) {
    //             console.log("callback马上回调1")
    //             app.userInfoReadyCallback()
    //           }
    //         }
    //       })*/
    //     }
    //   }
    // })
  },

  onShow: function () {
    let that = this;
    wx.getSystemInfo({
      success: res => {
        console.log('手机信息res'+res.model)
        let modelmes = res.model;
        if (modelmes.search('MI 8') != -1 || modelmes.search('iPhone X') != -1 ) {
          that.globalData.isIphoneX = true
        }
      }
    });
    common.queryGoodsByAppId("wx067ac066b8ee77fd", function (res) {
      app.globalData.xcxtype = res.list;
    });
  },

  getCityinfor: function (city) {
    for (var i = 0; i < 3; i++) {
      for (var j = 0; j < cities[i].length; j++) {
        if (cities[i][j].fullname.indexOf(city.trim()) > -1) {
          return cities[i][j].location.lat + "," + cities[i][j].location.lng;
        }
      }
    }
  },

  editTabBar: function () {
    var tabbar = this.globalData.tabbar,
      currentPages = getCurrentPages(),
      _this = currentPages[currentPages.length - 1],
      pagePath = _this.__route__;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
     
     var index="";
    for (var i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
      if (app.globalData.xcxtype.hasInfo=='0'){
        //为体验版，资讯不显示（修改为论坛，可能不显示）
        // if (tabbar.list[i].text=='资讯'){
        //   index=i;
        //   tabbar.list.splice(index, 1);
        // }
      }
    }
 
    _this.setData({
      tabbar: tabbar
    });
  },
 

  globalData: {
    myAdviser:{},
    xcxOpenId:'',
    shareBid:'',
    userInfo: null,
    getUserInfoFail:0,
    loading:false,
    isShareBack:false,//0：正常情况下1：分享进入2：分享页面返回了
    isIphoneX:false,//是不是iphoneX
    sendVerificationCode:true,//禁止短信重复发送
    isFind:true,//已授权
    isGoBack:false,
    isAuto:false,//判断是否是认证进入的
    qqmapsdk: new qqsdk({
      key: 'EJMBZ-QPFRP-RUYDA-VPHF3-YXXKE-3ZFYQ'
    }),
    city:'南京',
    isgoIndex:true,
    xcxtype:"",
    userInfo: null,
    tabbar: {
      color: "#808080",
      selectedColor: "#2f6faf",
      backgroundColor: "#000000",
      borderStyle: "black",
      list: [
        {
          selectedIconPath: "../../img/icon_shouyeed.png",
          iconPath: "../../img/icon_shouyegai.png",
          pagePath: "/pages/shouye/shouye",
          text: "首页",
          selected: true
        },
        {
          selectedIconPath: "../../img/icon_loupanxinxied.png",
          iconPath: "../../img/icon_loupanxinxi.png",
          pagePath: "/pages/detail/detail",
          text: "详情",
          selected: false
        },
        {
          selectedIconPath: "../../img/icon_xiangceed.png",
          iconPath: "../../img/icon_xiangce.png",
          pagePath: "/pages/photos/photos",
          text: "相册",
          selected: false
        }
      ],
      position: "bottom"
    }
  }
})
const app = getApp()